package org.hongzhisoft.dis.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hongzhisoft.dis.bean.User;
import org.hongzhisoft.dis.service.UserService;
import org.hongzhisoft.dis.service.impl.UserServiceImpl;

/**
 * 新增用户请求处理类
 * @author HongChengzhi
 *
 */
@WebServlet("/user/add")
public class UserAddServlet extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private UserService userService = new UserServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        String account = (String) req.getParameter("account");
        String password = (String) req.getParameter("password");
        String remark = (String) req.getParameter("remark");

        User user = new User();
        user.setAccount(account);
        user.setPassword(password);
        user.setRemark(remark);

        try {
            userService.saveUser(user);
            req.setAttribute("account", account);
            req.getRequestDispatcher("/add_success.jsp").forward(req, resp);
        } catch (Exception e) {
            throw new ServletException(e);
        }

    }

}
